﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading;

namespace Sencha.Direct.Client
{
    public abstract partial class RpcConnection
    {
        /// <summary>
        /// Request to remove service
        /// </summary>
        [DataContract]
        public sealed class OutgoingRequest
        {
			internal static IDictionary<string, object> EmptyArguments = new Dictionary<string, object>();

            /// <summary>
            /// Remote action
            /// </summary>
			[DataMember(Name = "method", Order = 3)]
            public string Action { get; set; }

            /// <summary>
            /// Remote controller
            /// </summary>
			[DataMember(Name = "action", Order = 4)]
            public string Controller { get; set; }

            /// <summary>
            /// Remote action arguments
            /// </summary>
			[DataMember(Name = "data", Order = 6)]
            public IDictionary<string, object> Arguments { get; set; }

			// obsolete in Sencha 4.0
			///// <summary>
			///// Remote action parameter names
			///// </summary>
			//[DataMember(Name = "paramNames", Order = 5)]
			//public string[] ParameterNames { get; set; }

            /// <summary>
            /// Request type - rpc
            /// </summary>
			[DataMember(Name = "type", Order = 2)]
            public string Type { get; set; }

            /// <summary>
            /// Request #
            /// </summary>
			[DataMember(Name = "tid", Order = 1)]
            public int TransactionId { get; set; }

            /// <summary>
            /// Async state
            /// </summary>
            [IgnoreDataMember]
            internal AsyncRequestResult AsyncResult { get; set; }

            /// <summary>
            /// Get string representation of request
            /// </summary>
            public override string ToString()
            {
                return string.Format("#{0} {1}.{2}({3})", this.TransactionId, this.Controller, this.Action, String.Join(", ", System.Linq.Enumerable.ToArray(this.Arguments.Keys)));
            }
        }
    }
}
